﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace HOOMT
{
    public abstract class BaseDAO
    {
        public static String connectionString = "Data Source=Sqlite/hoomt.sqlite;";
        public SQLiteConnection conn;
     //   public SQLiteDataReader reader;
      //  public SQLiteCommand cmd;

        public String projectName = "HOOMT";

        public SQLiteConnection GetConnection()
        {

            try
            {
                this.conn = new SQLiteConnection(connectionString);
                conn.Open();
                return conn;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return conn;
            }
        }
        public SQLiteCommand GetCmd()
        {
            try
            {
                this.conn = this.GetConnection();

                return conn.CreateCommand();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }



        public bool CloseConnection()
        {
            try
            {
                //if (this.reader != null)
                //    this.reader.Close();
                if (this.conn != null)
                    this.conn.Close();
                return true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }

        public String GetSimpleType(String strType)
        {
            int i = projectName.Length;
            return strType.Substring(i + 1);
        }

       
        
    }
}
